#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_EventDispatcher.h"

/* If you declare any globals in php_EventDispatcher.h uncomment this:
ZEND_DECLARE_MODULE_GLOBALS(EventDispatcher)
*/

/* True global resources - no need for thread safety here */
static int le_EventDispatcher;

ZEND_BEGIN_ARG_INFO_EX(arginfo_EventDispatcher_construct, 0, 0, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_EventDispatcher_addEventListener, 0, 0, 0)
	ZEND_ARG_INFO(0, type)
	ZEND_ARG_INFO(0, listener)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_EventDispatcher_hasEventListener, 0, 0, 0)
	ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_EventDispatcher_removeEventListener, 0, 0, 0)
	ZEND_ARG_INFO(0, type)
	ZEND_ARG_INFO(0, listener)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_EventDispatcher_dispatchEvent, 0, 0, 0)
//    ZEND_ARG_OBJ_INFO(0, event, Event, 0)
	ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()

/* {{{ EventDispatcher_functions[]
 *
 * Every user visible function must have an entry in EventDispatcher_functions[].
 */
const zend_function_entry EventDispatcher_functions[] = {
	PHP_ME(EventDispatcher, __construct, NULL, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
	PHP_ME(EventDispatcher, addEventListener, arginfo_EventDispatcher_addEventListener, ZEND_ACC_PUBLIC)
	PHP_ME(EventDispatcher, hasEventListener, arginfo_EventDispatcher_hasEventListener, ZEND_ACC_PUBLIC)
	PHP_ME(EventDispatcher, removeEventListener, arginfo_EventDispatcher_removeEventListener, ZEND_ACC_PUBLIC)
	PHP_ME(EventDispatcher, dispatchEvent, arginfo_EventDispatcher_dispatchEvent, ZEND_ACC_PUBLIC)
	{NULL, NULL, NULL}
};
/* }}} */

/* {{{ EventDispatcher_module_entry
 */
zend_module_entry EventDispatcher_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
	STANDARD_MODULE_HEADER,
#endif
	"EventDispatcher",
	EventDispatcher_functions,
	PHP_MINIT(EventDispatcher),
	PHP_MSHUTDOWN(EventDispatcher),
	PHP_RINIT(EventDispatcher),
	PHP_RSHUTDOWN(EventDispatcher),
	PHP_MINFO(EventDispatcher),
#if ZEND_MODULE_API_NO >= 20010901
	"0.1", /* Replace with version number for your extension */
#endif
	STANDARD_MODULE_PROPERTIES
};
/* }}} */

#ifdef COMPILE_DL_EVENTDISPATCHER
ZEND_GET_MODULE(EventDispatcher)
#endif

/* {{{ PHP_INI
 */
/* Remove comments and fill if you need to have entries in php.ini
PHP_INI_BEGIN()
    STD_PHP_INI_ENTRY("EventDispatcher.global_value",      "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_EventDispatcher_globals, EventDispatcher_globals)
    STD_PHP_INI_ENTRY("EventDispatcher.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_EventDispatcher_globals, EventDispatcher_globals)
PHP_INI_END()
*/
/* }}} */

/* {{{ php_EventDispatcher_init_globals
 */
/* Uncomment this function if you have INI entries
static void php_EventDispatcher_init_globals(zend_EventDispatcher_globals *EventDispatcher_globals)
{
	EventDispatcher_globals->global_value = 0;
	EventDispatcher_globals->global_string = NULL;
}
*/
/* }}} */

/* {{{ PHP_MINIT_FUNCTION
 */
PHP_MINIT_FUNCTION(EventDispatcher)
{
	/* If you have INI entries, uncomment these lines 
	REGISTER_INI_ENTRIES();
	*/
	return SUCCESS;
}
/* }}} */

/* {{{ PHP_MSHUTDOWN_FUNCTION
 */
PHP_MSHUTDOWN_FUNCTION(EventDispatcher)
{
	/* uncomment this line if you have INI entries
	UNREGISTER_INI_ENTRIES();
	*/
	return SUCCESS;
}
/* }}} */

/* Remove if there's nothing to do at request start */
/* {{{ PHP_RINIT_FUNCTION
 */
PHP_RINIT_FUNCTION(EventDispatcher)
{
	return SUCCESS;
}
/* }}} */

/* Remove if there's nothing to do at request end */
/* {{{ PHP_RSHUTDOWN_FUNCTION
 */
PHP_RSHUTDOWN_FUNCTION(EventDispatcher)
{
	return SUCCESS;
}
/* }}} */

/* {{{ PHP_MINFO_FUNCTION
 */
PHP_MINFO_FUNCTION(EventDispatcher)
{
	php_info_print_table_start();
	php_info_print_table_header(2, "EventDispatcher support", "enabled");
	php_info_print_table_end();

	/* Remove comments if you have entries in php.ini
	DISPLAY_INI_ENTRIES();
	*/
}
/* }}} */


/* Remove the following function when you have succesfully modified config.m4
   so that your module can be compiled into PHP, it exists only for testing
   purposes. */

/* Every user-visible function in PHP should document itself in the source */
/* {{{ proto string confirm_EventDispatcher_compiled(string arg)
   Return a string to confirm that the module is compiled in */
/*
PHP_FUNCTION(confirm_EventDispatcher_compiled)
{
	char *arg = NULL;
	int arg_len, len;
	char *strg;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
		return;
	}

	len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "EventDispatcher", arg);
	RETURN_STRINGL(strg, len, 0);
}*/
/* }}} */
